package dkbta.ontology.elements.pattern.conditions;

import dkbta.ontology.elements.Element;
import dkbta.ontology.values.DurationValues;

/**
 * A temporal condition that checks whether one element precedes another and the length of
 * the gap between the two elements
 * 
 * @author Uri Kanonov
 */
public class BeforeTemporalCondition extends TemporalCondition{
	/** Valid gap durations */
	private final DurationValues _validGapDuration;

	/**
	 * Initializes a before temporal condition
	 * 
	 * @param validGapDuration Valid gap durations
	 */
	public BeforeTemporalCondition(DurationValues validGapDuration){
		_validGapDuration = validGapDuration;
	}

	@Override
	public boolean checkCondition(Element first, Element second){
		long gapBetweenFirstAndSecond = second.getTimeInterval().getStartTime()
				- first.getTimeInterval().getEndTime();
		return _validGapDuration.isValid(gapBetweenFirstAndSecond);
	}

	@Override
	public String toString(){
		return "Before - Gap Values: " + _validGapDuration;
	}

}
